package com.bupt.liutong.admin.core.dao;

import java.util.List;

import com.bupt.liutong.admin.core.base.Ibatis;
import com.bupt.liutong.admin.core.dto.User;

public class UserDao {
	
	private Ibatis ibatis;
	
	@SuppressWarnings("unchecked")
	public List<User> getUsersByPage(User user){
		return (List<User>) ibatis.queryForPage("core_user.getUsers", user);
	}
	
	public User getUserByName(String userName){
		return (User) ibatis.queryForObject("core_user.getUserByName", userName);
	}
	
	@SuppressWarnings("unchecked")
	public List<User> getUserRolesByUserName(String userName){
		return (List<User>) ibatis.queryForList("core_user.getUserRolesByUserName", userName);
	}
	
	public void insertUser(User user){
		ibatis.insert("core_user.insertUser", user);
	}
	
	public void insertUserRole(User user){
		ibatis.insert("core_user.insertUserRole", user);
	}
	
	public int updateUser(User user){
		return ibatis.update("core_user.updateUser", user);
	}
	
	public int changePassword(User user){
		return ibatis.update("core_user.changePassword", user);
	}
	
	public int updateUserState(User user){
		return ibatis.update("core_user.updateUserState", user);
	}
	
	public int deleteUser(String userName){
		return ibatis.delete("core_user.deleteUser", userName);
	}
	
	public int deleteUserRoleByUserName(String userName){
		return ibatis.delete("core_user.deleteUserRoleByUserName", userName);
	}
	
	public void setIbatis(Ibatis ibatis) {
		this.ibatis = ibatis;
	}
}
